package stu.day19_day24.day20;

import java.util.Arrays;

public class LeetCode881 {
    public int numRescueBoats(int[] people, int limit) {

        Arrays.sort(people);
        int p = 0;
        int e = people.length-1;
        int num = 0;

        while (!(p>e)){
            if(people[e]>=limit){
                num += 1;
                e -= 1;
            } else if (people[e]+people[p]<=limit) {
                num += 1;
                e -= 1;
                p += 1;
            }else {
                num += 1;
                e -= 1;
            }
        }
        return num;


    }


}
